{extend name="public/common"}

{block name="style"}
<title>点对点教育VIP学员_测试提交</title>
<link rel="stylesheet" href="__HOME__/css/test/mui.picker.min.css">
<link rel="stylesheet" href="__HOME__/css/test/publish.css">
<style>
    .save{
        margin-top:25vw;
    }
    .sweet-alert h2 {
        color: #847d7d8f;
        font-size: 27px;
    }
    .sao {
        width: 12vw;
        margin-top: 4.5vw;
        margin-left: 1vw;
    }
    .list ul textarea {
        height: 20vw;
    }
    .list ul li {
        font-size: 1.8rem;
    }
    .top {
        width: 100%;
        font-size: 28px;
        color: #64a052;
        text-align: center;
        margin-bottom: 50px;
    }
    p {
        font-size: 1.8rem;
        margin-top: 0;
        margin-bottom: 10px;
        color: #8f8f94;
    }
    .top img {
        width: 160px;
        margin-top: 10px;
    }
</style>
{/block}

{block name="body"}
<div class="main">
    <div class="top">
        <img src="__ADMIN__/images/logo.png">
        <div>测 试 成 绩 录 入</div>
    </div>

    <div class="list">
        <ul>
            <li>
                测试时间：
                <input type="text" placeholder="...请输入时间" name="time" value="" id="date" readonly>
            </li>
            <li style="height: 24vw;padding: 2vw 0 0 2vw;">
                <textarea placeholder="...试卷信息（扫码获取）" style="border: 1px #ccc solid;width: 80%;font-size: 17px;padding: 0 2vw" readonly name="title"></textarea>
                <img src="__HOME__/images/test/sao.png" class="sao">
                <input type="hidden"  name="code" value="">
            </li>
            <li>
                测试成绩：
                <input type="text" placeholder="...请输入成绩" name="tel" value="">
            </li>
        </ul>
    </div>
    <div class="save">提&emsp;交</div>
    <a href="{:url('Test/testlist')}" class="goreview" style="display: block;color: #64a052">查看测试记录 >>></a>
</div>
<div class="showbox">
    <div class="loader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"/>
        </svg>
    </div>
</div>
{/block}

{block name="script"}

<script src="__HOME__/js/mui.min.js"></script>
<script src="__HOME__/js/mui.picker.min.js"></script>
<script src="__HOME__/js/jquery-1.12.1.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=WS7BZ-ZBERG-5T5Q3-IBRHI-FVXU3-45FR5&libraries=drawing,geometry,autocomplete,convertor"></script>
<script>
    $('title' ).text('点对点教育VIP学员_测试提交');
    $(".showbox").hide();
    //关闭分享
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
    var appId='{$jsSign.appId}';
    var timestamp="{$jsSign['timestamp']}";
    var nonceStr='{$jsSign.nonceStr}';
    var signature='{$jsSign.signature}';
    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: appId, // 必填，公众号的唯一标识
        timestamp: timestamp, // 必填，生成签名的时间戳
        nonceStr: nonceStr, // 必填，生成签名的随机串
        signature: signature,// 必填，签名，见附录1
        jsApiList: ['scanQRCode','getLocation'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
    wx.ready(function(){
        $('.sao').click(function(){
            wx.scanQRCode({
                desc: 'scanQRCode desc',
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function (res) {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    $.ajax({
                        type:'post',
                        url: "{:Url('Test/scan')}",
                        data: {code:result} ,
                        success:function(data){
                            if(data.status==2){
                                swal({
                                    title: ' ',
                                    text: '请扫描正确的试卷二维码',
                                    type: 'error',
                                    showConfirmButton:false,
                                    timer:2000
                                });
                            }else{
                                $("input[name='code']").val(data.code);
                                $("textarea[name='title']").val(data.title);
                            }

                        }
                    });
                },
                error:function(){
                    swal({
                        title: ' ',
                        text: '系统参数错误~请重试',
                        type: 'error',
                        showConfirmButton:false,
                        timer:2000
                    });
                }
            });
        });
    });
    $(".save").on("click",function(){
        var single = false;
        if($("input[name='time']").val()==""||$("input[name='tel']").val()==""||$("input[name='code']").val()==""){
            single = false
        }else{
            var num = $("input[name='tel']").val()
            var match = num.match(/^\d+(\.\d+)?$/);   //考虑小数写法 ^\d+(\.\d+)?$
            if(num != '' && match) {
                single = true;
            } else {
                swal({
                    title: ' ',
                    text: '成绩输入格式有误',
                    type: 'error',
                    showConfirmButton:false,
                    timer:1500
                });
                return false;
            }
        }
        if(single){
            var data = {
                code:$("input[name='code']").val(),
                test_time: $("input[name='time']").val(),
                score: $("input[name='tel']").val(),
            };

            $.ajax({
                type:"post",
                url: "{:Url('Test/index')}",
                data:data,
                beforeSend: function(XMLHttpRequest){
                    $(".showbox").show();
                },
                success:function(data){
                    $(".showbox").hide();
                    if(data.code == 1){
                        swal({
                            title: "提交成功",
                            type: 'success',
                            showCancelButton: false,
                            confirmButtonText: "确定",
                            allowOutsideClick:false
                        });
                        setTimeout(function(){
                            location.reload();
                        },1500)
                    }else{
                        swal({
                            title: ' ',
                            text: data.msg,
                            type: 'error',
                            showConfirmButton:false,
                            timer:1500
                        });
                    }
                }
            });
        }else{
            swal({
                title: ' ',
                text: '信息输入不完整',
                type: 'error',
                showConfirmButton:false,
                timer:1500
            });
        }
    })

    var dtpicker = new mui.DtPicker({
        "type": "datetime",
        "value": ""
    })
    document.querySelector('#date').addEventListener('tap', function () {
        dtpicker.show(function (e) {
            document.getElementById('date').value = e.text;
        })
    })
    options = {
        scrollY: true, //是否竖向滚动
        scrollX: false, //是否横向滚动
        startX: 0, //初始化时滚动至x
        startY: 0, //初始化时滚动至y
        indicators: false, //是否显示滚动条
        deceleration:0.0006, //阻尼系数,系数越小滑动越灵敏
        bounce: true //是否启用回弹
    };

    mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
</script>
{/block}